const jwt = require('jsonwebtoken');
module.exports = class extends think.Controller {
  async __before() {
    think.config('mypath', 'miniprogram/1.01');
    const that = this;
    const token = that.ctx.header['user-token'];
    if (token) {
      // 验证token
      try {
        const res = jwt.verify(token, think.config('mytmini.jwtSecret'));
        think.openid = res.openid;
      } catch (e) {
        return that.json({statusCode: '100', msg: '身份验证失败,请重新验证'});
      }
    }
  }

  // 获取当前登录用户
  getuseropenid() {
    return think.openid;
  }
};
